import mixin from '../../../AddParkingLot/AddParkingLotComponents/rule/opt';
import utils from '@/mixins/utils.js';
 let carTypeOpt = [
							{
								name: '蓝牌车',
								value: 1
							},
							{
								name: '黄牌车',
								value: 2
							},
							{
								name: '新能源小车',
								value: 4
							},
							{
								name: '新能源大车',
								value: 3
							}
						];
export default {
  mixins: [mixin, utils],
  data() {
    return {
      parkBaseInfo: null,
      originRule: null,
      originData: null,
      pageChargeList: {
        parkChargeBaseVoList: null
      },
      delRuleList: {},
      carTypeOpt,
      defaultRuleItem: null
    };
  },
  created() {
    this.getOperatorParkBasicCharge();
  },
  methods: {
    getOperatorParkBasicCharge() {
      const self = this;
      var params = {
        parkID: this.$route.query.parkId
      };
      API.fetchGet('/operatorPark/getOperatorParkBasicCharge', params).then(
        res => {
          if (res.data) {
            this.parkBaseInfo = JSON.parse(JSON.stringify(res.data.parkBaseInfo));
            this.originRule = JSON.parse(JSON.stringify(res.data.parkChargeBaseVoList));
            this.originData = JSON.parse(JSON.stringify(res.data));

            this.getDefaultRuleItem()

            if (!this.$route.query.isAddRule) {
              res.data.parkChargeBaseVoList = res.data.parkChargeBaseVoList.filter(item => item.chargeTypeSeq === Number(this.$route.query.chargeTypeSeq));

              res.data.parkChargeBaseVoList.forEach(item => {
                const isDefault = item.isDefault;
                item.uiOpt = {
                  carTypeOpt: this.carTypeOpt,
                  ruleCarType:
                    item.parkChargeStandardVoList.length === 1 &&
                    item.parkChargeStandardVoList[0].carType === 0
                      ? '不区分'
                      : '区分',
                  curCarType: 1
                };
  
                if (item.parkChargeStandardVoList && item.parkChargeStandardVoList.length) {
                  if (item.parkChargeStandardVoList[0].type === 1 && item.parkChargeStandardVoList.length === 1) {
                    item.isFree = '免费车场';
                  } else {
                    item.isFree = '收费车场';
                  }
                  item.parkChargeStandardVoList.forEach(citem => {
                    let uiOpt = {
                      splitTimeOpt: ['不分时段', '分时段'],
                      curSplitTime:
                        citem.parkChargeStandardPeriodVoList && citem.parkChargeStandardPeriodVoList.length < 2
                          ? '不分时段'
                          : '分时段',
                      splitTimeCount: citem.parkChargeStandardPeriodVoList.length,
                      isMaxCharge: citem.maxCharge !== null ? true : false,
                      customIsMaxCharge: citem.customMaxCharge !== null && citem.customMaxUnit !== null ? true : false
                    };
  
                    citem.uiOpt = uiOpt;
  
                    if (citem.parkChargeStandardPeriodVoList && citem.parkChargeStandardPeriodVoList.length) {
                      citem.parkChargeStandardPeriodVoList.forEach(ccitem => {
                        let uiOpt = {
                          ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
                          curRuleType: '按次定额收费',
                          isMaxCharge: false,
                          isShowDetail: false
                        };
  
                        const curStyleItem = ccitem.parkChargeStandardPeriodDetailVoList[0];
                        if (curStyleItem.chargeType === 3 && curStyleItem.chargeUnit === 1) {
                          uiOpt.curRuleType = '按次定额收费';
                        }
  
                        if (curStyleItem.chargeType === 1) {
                          uiOpt.curRuleType = '按单价收费';
                          if (ccitem.maxCharge !== null && ccitem.maxCharge > 0) {
                            uiOpt.isMaxCharge = true;
                          }
                        }
  
                        if (curStyleItem.chargeType === 2 && curStyleItem.stepType === 1) {
                          uiOpt.curRuleType = '递增收费';
                          if (ccitem.maxCharge !== null && ccitem.maxCharge > 0) {
                            uiOpt.isMaxCharge = true;
                          }
  
                          const isHasXunHuanRule = ccitem.parkChargeStandardPeriodDetailVoList.filter(item => {
                            return item.chargeType === 2 && item.stepType === 2;
                          }).length;
  
                          if (!!isHasXunHuanRule) {
                            ccitem.isHasXunhuan = true;
                          } else {
                            ccitem.isHasXunhuan = false;
                          }
                        }
                        ccitem.uiOpt = uiOpt;
  
                      });
                    }
                  });
                } else {
                  item.isFree = '免费车场';
                }
              });

              this.pageChargeList.parkChargeBaseVoList = res.data.parkChargeBaseVoList;

            } else if (this.$route.query.isAddRule === true || this.$route.query.isAddRule === 'true') {
              this.pageChargeList.parkChargeBaseVoList = [
                {
                  typeName: '',
                  actionType: 0,
                  carType: false,
                  chargeTypeSeq: 0,
                  isDefault: false,
                  isFree: '收费车场',
                  uiOpt: {
                    carTypeOpt: this.carTypeOpt,
                    ruleCarType: '不区分',
                    curCarType: 1
                  },
                  parkChargeStandardVoList: [
                    {
                      uiOpt: {
                        splitTimeOpt: ['不分时段', '分时段'],
                        curSplitTime: '不分时段',
                        splitTimeCount: 2,
                        isMaxCharge: false,
                        customIsMaxCharge: false,
                      },
                      actionType: 0,
                      carType: 0,
                      chargeTypeSeq: 0,
                      chargeUnit: '',
                      cmxSettleType: 0,
                      customMaxCharge: '',
                      customMaxUnit: '',
                      freeTime: '',
                      freeTimeAcc: true,
                      loopType: 1,
                      maxCharge: 0,
                      minCharge: 0,
                      mxSettleType: 0,
                      natureDay: 0,
                      natureFreeTime: 0,
                      parkChargeStandardPeriodVoList: [
                        {
                          uiOpt: {
                            ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
                            curRuleType: '按次定额收费',
                            isShowDetail: true,
                            isMaxCharge: false
                          },
                          maxCharge: 0,
                          mxSettleType: 0,
                          parkChargeStandardPeriodDetailVoList: [
                            {
                              chargeAmount: '',
                              chargeType: 3,
                              chargeUnit: 1,
                              periodDetailSeq: '',
                              standardPeriodSeq: '',
                              stepType: null
                            }
                          ],
                          standardPeriodSeq: '',
                          standardSeq: '',
                          timeArray: ['00:00:00', '23:59:59']
                        }
                      ],
                      remark: '',
                      standardName: '不区分收费规则',
                      standardSeq: 0,
                      startTime: '00:00:00',
                      type: 0
                    }
                  ]
                }
              ]
            }
          }
        },
        err => {}
      );
    },

    getDefaultRuleItem() {
      this.defaultRuleItem = this.originRule.find(item => item.isDefault === true)
    },

    setDefaultRuleGroup(val) {
      if (!val) {
        let item = this.originRule.find(item => item.chargeTypeSeq === this.defaultRuleItem.chargeTypeSeq)
        item.isDefault = true;
        item.actionType = 3
      } else {
        let item = this.originRule.find(item => item.chargeTypeSeq === this.defaultRuleItem.chargeTypeSeq)
        item.isDefault = false;
        item.actionType = 1;
      }
    },
    changeChargeRuleType(val, parkChargeBaseVoListItem, chargeTypeSeq, carTypeOpt) {
      let old_data = {};
      if (parkChargeBaseVoListItem.parkChargeStandardVoList[0].standardSeq > 0) {
        old_data = {
          actionType: parkChargeBaseVoListItem.parkChargeStandardVoList[0].actionType,
          standardSeq: parkChargeBaseVoListItem.parkChargeStandardVoList[0].standardSeq,
          chargeTypeSeq: parkChargeBaseVoListItem.parkChargeStandardVoList[0].chargeTypeSeq
        };
      }
      if (val === '免费车场') {
        parkChargeBaseVoListItem.parkChargeStandardVoList.forEach((item, index) => {
          if (index >= 1 && item.chargeTypeSeq && item.actionType !== 0) {
            item.actionType = 2;
            if (this.delRuleList[chargeTypeSeq]) {
              this.delRuleList[chargeTypeSeq].push(item);
            } else {
              this.delRuleList[chargeTypeSeq] = [];
              this.delRuleList[chargeTypeSeq].push(item);
            }
          }
        });

        parkChargeBaseVoListItem.carType = false;
        let init_data = {
          actionType: 0,
          carType: 0,
          chargeTypeSeq: 0,
          chargeUnit: '',
          cmxSettleType: 0,
          customMaxCharge: '',
          customMaxUnit: '',
          freeTime: '',
          freeTimeAcc: false,
          loopType: 1,
          maxCharge: 0,
          minCharge: 0,
          mxSettleType: 0,
          natureDay: 0,
          natureFreeTime: 0,
          parkChargeStandardPeriodVoList: [],
          remark: '',
          standardName: '默认免费规则',
          standardSeq: 0,
          startTime: '00:00:00',
          type: 1
        };
        let new_data = Object.assign(init_data, old_data);
        parkChargeBaseVoListItem.parkChargeStandardVoList = [new_data];
        parkChargeBaseVoListItem.uiOpt = {
          ruleCarType: '不区分'
        }
      }

      if (val === '收费车场') {
        let init_data = {
          uiOpt: {
            splitTimeOpt: ['不分时段', '分时段'],
            curSplitTime: '不分时段',
            splitTimeCount: 2,
            isMaxCharge: false,
            customIsMaxCharge: false,
          },
          actionType: 0,
          carType: 0,
          chargeTypeSeq: 0,
          chargeUnit: '',
          cmxSettleType: 0,
          customMaxCharge: '',
          customMaxUnit: '',
          freeTime: '',
          freeTimeAcc: true,
          loopType: 1,
          maxCharge: 0,
          minCharge: 0,
          mxSettleType: 0,
          natureDay: 0,
          natureFreeTime: 0,
          parkChargeStandardPeriodVoList: [
            {
              uiOpt: {
                ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
                curRuleType: '按次定额收费',
                isShowDetail: true,
                isMaxCharge: false
              },
              maxCharge: 0,
              mxSettleType: 0,
              parkChargeStandardPeriodDetailVoList: [
                {
                  chargeAmount: '',
                  chargeType: 3,
                  chargeUnit: 1,
                  periodDetailSeq: '',
                  standardPeriodSeq: '',
                  stepType: null
                }
              ],
              standardPeriodSeq: '',
              standardSeq: '',
              timeArray: ['00:00:00', '23:59:59']
            }
          ],
          remark: '',
          standardName: '不区分收费规则',
          standardSeq: 0,
          startTime: '00:00:00',
          type: 0
        };
        let new_data = Object.assign(init_data, old_data);
        parkChargeBaseVoListItem.parkChargeStandardVoList = [new_data];
        parkChargeBaseVoListItem.uiOpt = {
          carTypeOpt: this.carTypeOpt,
          ruleCarType: '不区分',
          curCarType: 1
        }

      }
    },
    changeCarType(val, parkChargeBaseVoListItem) {
      parkChargeBaseVoListItem.parkChargeStandardVoList.forEach(item => {
        if (item.actionType !== 0 && item.chargeTypeSeq) {
          item.actionType = 2;
          if (this.delRuleList[parkChargeBaseVoListItem.chargeTypeSeq]) {
            this.delRuleList[parkChargeBaseVoListItem.chargeTypeSeq].push(item);
          } else {
            this.delRuleList[parkChargeBaseVoListItem.chargeTypeSeq] = [];
            this.delRuleList[parkChargeBaseVoListItem.chargeTypeSeq].push(item);
          }
        }
      })


      let initData = {
          uiOpt: {
            splitTimeOpt: ['不分时段', '分时段'],
            curSplitTime: '不分时段',
            splitTimeCount: 2,
            isMaxCharge: false,
            customIsMaxCharge: false,
          },
          actionType: 0,
          carType: 0,
          chargeTypeSeq: 0,
          chargeUnit: '',
          cmxSettleType: 0,
          customMaxCharge: '',
          customMaxUnit: '',
          freeTime: '',
          freeTimeAcc: true,
          loopType: 1,
          maxCharge: 0,
          minCharge: 0,
          mxSettleType: 0,
          natureDay: 0,
          natureFreeTime: 0,
          parkChargeStandardPeriodVoList: [
            {
              uiOpt: {
                ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
                curRuleType: '按次定额收费',
                isShowDetail: true,
                isMaxCharge: false,
              },
              maxCharge: 0,
              mxSettleType: 0,
              parkChargeStandardPeriodDetailVoList: [
                {
                  chargeAmount: '',
                  chargeType: 3,
                  chargeUnit: 1,
                  periodDetailSeq: '',
                  standardPeriodSeq: '',
                  stepType: null
                }
              ],
              standardPeriodSeq: '',
              standardSeq: '',
              timeArray: ['00:00:00', '23:59:59']
            }
          ],
          remark: '',
          standardName: '不区分收费规则',
          standardSeq: 0,
          startTime: '00:00:00',
          type: 0
        }
      if (val === '不区分') {
        parkChargeBaseVoListItem.parkChargeStandardVoList = [initData]
      } else if (val === '区分') {
        let temp = []
        const standarNameList = {
          1: '蓝牌车收费规则',
          2: '黄牌车收费规则',
          4: '新能源小车收费规则',
          3: '新能源大车收费规则',
        }
        this.carTypeOpt.forEach(item => {
          let initDataCopy =  JSON.parse(JSON.stringify(initData))
          initDataCopy.carType = item.value;
          initDataCopy.standardName = standarNameList[item.value]
          temp.push(initDataCopy)
        })
        parkChargeBaseVoListItem.parkChargeStandardVoList = JSON.parse(JSON.stringify(temp));
      }
    }, 
    expandAndCollapse(item) {
      item.uiOpt.isShowDetail = !item.uiOpt.isShowDetail
    },
    setChargeRuleIsTimes(val, parkChargeStandardVoListItem) {
      if (val === '不分时段') {
        parkChargeStandardVoListItem.mxSettleType = 0;
        parkChargeStandardVoListItem.cmxSettleType = 0;

        parkChargeStandardVoListItem.parkChargeStandardPeriodVoList = [
          {
            uiOpt: {
              ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
              curRuleType: '按次定额收费',
              isShowDetail: true,
              isMaxCharge: false,
            },
            maxCharge: 0,
            mxSettleType: 0,
            parkChargeStandardPeriodDetailVoList: [
              {
                chargeAmount: '',
                chargeType: 3,
                chargeUnit: 1,
                periodDetailSeq: '',
                standardPeriodSeq: '',
                stepType: null
              }
            ],
            standardPeriodSeq: '',
            standardSeq: '',
            timeArray: ['00:00:00', '23:59:59']
          }
        ];
      }

      if (val === '分时段') {
        parkChargeStandardVoListItem.mxSettleType = 1;
        parkChargeStandardVoListItem.cmxSettleType = 1;
        parkChargeStandardVoListItem.parkChargeStandardPeriodVoList = [
          {
            uiOpt: {
              ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
              curRuleType: '按次定额收费',
              isMaxCharge: false,
              isShowDetail: true
            },
            maxCharge: 0,
            mxSettleType: 0,
            parkChargeStandardPeriodDetailVoList: [
              {
                chargeAmount: '',
                chargeType: 3,
                chargeUnit: 1,
                periodDetailSeq: '',
                standardPeriodSeq: '',
                stepType: null
              }
            ],
            standardPeriodSeq: '',
            standardSeq: '',
            timeArray: ['00:00:00', '23:59:59']
          },
          {
            uiOpt: {
              ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
              curRuleType: '按次定额收费',
              isMaxCharge: false,
              isShowDetail: true
            },
            maxCharge: 0,
            mxSettleType: 0,
            parkChargeStandardPeriodDetailVoList: [
              {
                chargeAmount: '',
                chargeType: 3,
                chargeUnit: 1,
                periodDetailSeq: '',
                standardPeriodSeq: '',
                stepType: null
              }
            ],
            standardPeriodSeq: '',
            standardSeq: '',
            timeArray: ['00:00:00', '23:59:59']
          }
        ];
      }
    },
    timeRuleChange(val, item) {
      if (val === '按次定额收费') {
        item.uiOpt.isMaxCharge = false;
        item.maxCharge = 0;
        item.parkChargeStandardPeriodDetailVoList = [
          {
            chargeAmount: '',
            chargeType: 3,
            chargeUnit: 1,
            periodDetailSeq: '',
            standardPeriodSeq: '',
            stepType: null
          }
        ];
      }
      if (val === '按单价收费') {
        item.parkChargeStandardPeriodDetailVoList = [
          {
            chargeAmount: '',
            chargeType: 1,
            chargeUnit: '',
            periodDetailSeq: '',
            standardPeriodSeq: '',
            stepType: ''
          }
        ];
      }
      if (val === '递增收费') {
        item.isHasXunhuan = true;
        item.parkChargeStandardPeriodDetailVoList = [
          {
            chargeAmount: '',
            chargeType: 2,
            chargeUnit: '',
            periodDetailSeq: '',
            standardPeriodSeq: '',
            stepType: 1
          },
          {
            chargeAmount: '',
            chargeType: 2,
            chargeUnit: '',
            periodDetailSeq: '',
            standardPeriodSeq: '',
            stepType: 2
          }
        ];
      }
    },
    timeRuleMaxChargeChange(val, item) {
      if (!val) {
        item.maxCharge = 0;
      }
    },
    addDingE_RuleItem(detailList) {
      detailList.push({
        chargeAmount: '',
        chargeType: 2,
        chargeUnit: '',
        periodDetailSeq: '',
        standardPeriodSeq: '',
        stepType: 1
      });
    },
    addXunHuan_RuleItem(ruleItem, detailList) {
      ruleItem.isHasXunhuan = true;
      detailList.push({
        chargeAmount: '',
        chargeType: 2,
        chargeUnit: '',
        periodDetailSeq: '',
        standardPeriodSeq: '',
        stepType: 2
      });
    },
    delRuleItemDetailItem(list, index) {
      list.splice(index, 1);
    },
    delParkChargeStandardPeriodVoListItem(item, list, index) {
      item.uiOpt.splitTimeCount--;
      list.splice(index, 1);
    },
    delRuleItemDetailXunHuanItem(ruleItem, list, index) {
      ruleItem.isHasXunhuan = false;
      list.splice(index, 1);
    },
    splitTimeChange(val, list) {
      if (val > list.length) {
        for (let i = 0, len = val - list.length; i < len; i++) {
          list.push({
            uiOpt: {
              ruleTypeOpt: ['按次定额收费', '按单价收费', '递增收费'],
              curRuleType: '按次定额收费',
              isShowDetail: true,
              isMaxCharge: false,
            },
            maxCharge: '',
            isMaxCharge: false,
            mxSettleType: 0,
            parkChargeStandardPeriodDetailVoList: [
              {
                chargeAmount: '',
                chargeType: 3,
                chargeUnit: 1,
                periodDetailSeq: '',
                standardPeriodSeq: '',
                stepType: null
              }
            ],
            standardPeriodSeq: '',
            standardSeq: '',
            timeArray: ['00:00:00', '23:59:59']
          });
        }
      }
      if (list.length > val) {
        list.splice(-(list.length - val), list.length - val);
      }
    },
    customIsMaxChargeChange(val, item) {
      if (!val) {
        item.customMaxUnit = '';
        item.customMaxCharge = '';
      }
    },
    isMaxChargeChange(val, item) {
      if (!val) {
        item.maxCharge = '';
      }
    },
    testXunHuanRule() {
      const self = this;
      // 递增收费如果全部是定额，时段内的定额分钟数的最大值必须等于时段分钟数，否则必须加上循环
      let result = [];
      this.pageChargeList.parkChargeBaseVoList.forEach(item => {
        item.parkChargeStandardVoList.forEach(citem => {
          // 不分时段递增收费
          if (
            citem.parkChargeStandardPeriodVoList.length === 1 &&
            citem.parkChargeStandardPeriodVoList[0].uiOpt.curRuleType === '递增收费'
          ) {
            const has_xun_huan_rule = citem.parkChargeStandardPeriodVoList[0].parkChargeStandardPeriodDetailVoList.filter(
              item => item.chargeType === 2 && item.stepType === 2
            );
            if (!has_xun_huan_rule.length) {
              let max_chargeUnit = 0;
              citem.parkChargeStandardPeriodVoList[0].parkChargeStandardPeriodDetailVoList.forEach(ccitem => {
                if (ccitem.chargeUnit > max_chargeUnit) {
                  max_chargeUnit = ccitem.chargeUnit;
                }
              });
              if (max_chargeUnit !== 1440) {
                let carType = this.opts.carTypeOpt.filter(item => item.value === citem.carType)[0].name;
                result.push(`${item.typeName}，${carType}`);
              }
            }
          }
          // 分时段
          if (citem.parkChargeStandardPeriodVoList.length > 1) {
            citem.parkChargeStandardPeriodVoList.forEach((pitem, index) => {
              if (pitem.uiOpt.curRuleType === '递增收费') {
                const has_xun_huan_rule = pitem.parkChargeStandardPeriodDetailVoList.filter(
                  item => item.chargeType === 2 && item.stepType === 2
                );

                if (!has_xun_huan_rule.length) {
                  let max_chargeUnit = 0;
                  citem.parkChargeStandardPeriodVoList[0].parkChargeStandardPeriodDetailVoList.forEach(ccitem => {
                    if (ccitem.chargeUnit > max_chargeUnit) {
                      max_chargeUnit = ccitem.chargeUnit;
                    }
                  });
                  const time_range_minutes = self.getRangTimeMinutes(pitem.timeArray);
                  if (time_range_minutes.residue !== 0 || max_chargeUnit !== time_range_minutes.minutes) {
                    let carType = this.opts.carTypeOpt.filter(item => item.value === citem.carType)[0].name;
                    result.push(`${item.typeName}，${carType}时段${index + 1}`);
                  }
                }
              }
            });
          }
        });
      });
      return result;
    },
    getRangTimeMinutes(timeArray) {
      const start_time = this.getRuleRangTime(timeArray[0]);
      const end_time = this.getRuleRangTime(timeArray[1], 'end');
      let rang;
      const day_rang = 24 * 60 * 60 * 1000;
      if (start_time >= end_time) {
        rang = end_time + day_rang - start_time;
      } else {
        rang = end_time - start_time;
      }
      return {
        residue: rang % (60 * 1000),
        minutes: rang / (60 * 1000)
      };
    },
    getRuleRangTime(time, type) {
      const d = new Date();
      if (
        type === 'end' &&
        new Date([d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/') + ' ' + time).getMinutes() === 59
      ) {
        return new Date([d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/') + ' ' + time).getTime() + 1000;
      } else {
        return new Date([d.getFullYear(), d.getMonth() + 1, d.getDate()].join('/') + ' ' + time).getTime();
      }
    },
    async saveEdit() {
      const testRule = await this.testRule();
      if (testRule) {
        const isTestXunHuanRule = this.testXunHuanRule();
        if (isTestXunHuanRule.length) {
          let tips_string_html = isTestXunHuanRule.map(item => {
            const timeRange = item.includes('时段') ? '分时段' : '不分时段';
            if (timeRange === '不分时段') {
              return `<p>${item}收费规则配置错误</p><p style="margin-bottom: 10px">提示：不分时段递增收费规则，必须有一条规则的分钟数等于1440</p>`;
            } else if (timeRange === '分时段') {
              return `<p>${item}收费规则配置错误</p><p style="margin-bottom: 10px">提示：分时段递增收费规则，配置的分钟数必须等于时段内分钟数</p>`;
            }
          });
          this.$alert(tips_string_html.join(''), '收费规则配置错误', {
            confirmButtonText: '确定',
            customClass: 'mgr-msg-box rule-tips',
            confirmButtonClass: 'el-button el-button--danger',
            dangerouslyUseHTMLString: true
          });
          return;
        }
        this.submitNormalRules();
      }
    },

  
    submitNormalRules() {
      let saveData = {
        domain: this.originData.domain,
        parkBaseInfo: this.parkBaseInfo,
        parkChargeBaseVoList: this.setRuleActionType(this.pageChargeList.parkChargeBaseVoList)
      };

      API.fetchPost('/operatorPark/saveOperatorParkBasicCharge', saveData).then(
        res => {
          if (res.status === 1) {
            this.showToast('操作成功', 1, 1500);
            this.back();
          } else {
            this.showToast('操作失败!', 2, 1500);
          }
        },
        err => {
          console.log(err);
        }
      );
    },

    back() {
      this.$router.push({
        name: 'allParkinglotInfo',
        query: this.$route.query
      });
    },

    setRuleActionType(curList) {
      let _curList = JSON.parse(JSON.stringify(curList));
      const self = this;
      _curList.forEach(item => {
        delete item['uiOpt'];
        delete item['isFree'];

        const oldItem = self.getRuleGroupItem(item.chargeTypeSeq);
        if (item.parkChargeStandardVoList && item.parkChargeStandardVoList.length && oldItem) {
          item.parkChargeStandardVoList.forEach(citem => {
            delete citem['uiOpt'];
            if (citem.parkChargeStandardPeriodVoList && citem.parkChargeStandardPeriodVoList.length) {
              citem.parkChargeStandardPeriodVoList.forEach(ccitem => {
                delete ccitem['uiOpt'];
                delete ccitem['isHasXunhuan'];
              });
            }
            if (citem.actionType !== 0) {
              const old_citem = self.getRuleItem(oldItem, citem.standardSeq);
              if (!self.isEq(citem, old_citem)) {
                citem.actionType = 1;
              }
            }
          });
        }
        if (oldItem && !self.isEq(item, oldItem)) {
          item.actionType = 1;
        }

        if (this.delRuleList[item.chargeTypeSeq] && this.delRuleList[item.chargeTypeSeq].length) {
          item.parkChargeStandardVoList = item.parkChargeStandardVoList.concat(this.delRuleList[item.chargeTypeSeq]);
        }
      });
      let otherRuleList = this.originRule.filter(item => item.chargeTypeSeq !== _curList[0].chargeTypeSeq)
      return _curList.concat(otherRuleList)
    },

    getRuleGroupItem(chargeTypeSeq) {
      return this.originRule.filter(item => item.chargeTypeSeq === chargeTypeSeq)[0];
    },

    getRuleItem(oldItem, standardSeq) {
      return oldItem.parkChargeStandardVoList.filter(item => item.standardSeq === standardSeq)[0];
    },


    testRule() {
      const self = this;
      let test = [];
      return new Promise((resolve, reject) => {
        const testRuleItem = testItemIndex => {
          let result;
          this.$refs['pageChargeList'][testItemIndex].validate(valid => {
            if (valid) {
              result = true;
            } else {
              result = false;
            }
          });
          return result;
        };
        this.pageChargeList.parkChargeBaseVoList.forEach((item, index) => {
          test.push(testRuleItem(index));
        });

        if (!test.includes(false)) {
          resolve(true);
        } else {
          resolve(false);
        }
      });
    },

    testSpecialListRule() {
      return new Promise((resolve, reject) => {
        console.log(this.$refs['parkSpecialChargeVoList']);
        this.$refs['parkSpecialChargeVoList'].validate(valid => {
          if (valid) {
            resolve(true);
          } else {
            resolve(false);
          }
        });
      });
    },

    isEq(obj1, obj2) {
      var toString = Object.prototype.toString;

      function isFunction(obj) {
        return toString.call(obj) === '[object Function]';
      }

      function eq(a, b, aStack, bStack) {
        // === 结果为 true 的区别出 +0 和 -0
        if (a === b) return a !== 0 || 1 / a === 1 / b;

        // typeof null 的结果为 object ，这里做判断，是为了让有 null 的情况尽早退出函数
        if (a == null || b == null) return false;

        // 判断 NaN
        if (a !== a) return b !== b;

        // 判断参数 a 类型，如果是基本类型，在这里可以直接返回 false
        var type = typeof a;
        if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;

        // 更复杂的对象使用 deepEq 函数进行深度比较
        return deepEq(a, b, aStack, bStack);
      }

      function deepEq(a, b, aStack, bStack) {
        // a 和 b 的内部属性 [[class]] 相同时 返回 true
        var className = toString.call(a);
        if (className !== toString.call(b)) return false;

        switch (className) {
          case '[object RegExp]':
          case '[object String]':
            return '' + a === '' + b;
          case '[object Number]':
            if (+a !== +a) return +b !== +b;
            return +a === 0 ? 1 / +a === 1 / b : +a === +b;
          case '[object Date]':
          case '[object Boolean]':
            return +a === +b;
        }

        var areArrays = className === '[object Array]';
        // 不是数组
        if (!areArrays) {
          // 过滤掉两个函数的情况
          if (typeof a != 'object' || typeof b != 'object') return false;

          var aCtor = a.constructor,
            bCtor = b.constructor;
          // aCtor 和 bCtor 必须都存在并且都不是 Object 构造函数的情况下，aCtor 不等于 bCtor， 那这两个对象就真的不相等啦
          if (
            aCtor !== bCtor &&
            !(isFunction(aCtor) && aCtor instanceof aCtor && isFunction(bCtor) && bCtor instanceof bCtor) &&
            ('constructor' in a && 'constructor' in b)
          ) {
            return false;
          }
        }

        aStack = aStack || [];
        bStack = bStack || [];
        var length = aStack.length;

        // 检查是否有循环引用的部分
        while (length--) {
          if (aStack[length] === a) {
            return bStack[length] === b;
          }
        }

        aStack.push(a);
        bStack.push(b);

        // 数组判断
        if (areArrays) {
          length = a.length;
          if (length !== b.length) return false;

          while (length--) {
            if (!eq(a[length], b[length], aStack, bStack)) return false;
          }
        }
        // 对象判断
        else {
          var keys = Object.keys(a),
            key;
          length = keys.length;

          if (Object.keys(b).length !== length) return false;
          while (length--) {
            key = keys[length];
            if (!(b.hasOwnProperty(key) && eq(a[key], b[key], aStack, bStack))) return false;
          }
        }

        aStack.pop();
        bStack.pop();
        return true;
      }
      return eq(obj1, obj2);
    },
    checkUnit(rule, value, callback) {
      const integer_reg = /^[1-9]\d*$/
      if (value === '') {
        callback(new Error('时间不能为空'));
      } else if (!integer_reg.test(value)) {
        callback(new Error('必须是大于0的整数'));
      } else {
        callback();
      }
    },
    checkFreeUnit(rule, value, callback) {
      const integer_reg = /^[0-9]\d*$/
      if (value === '') {
        callback(new Error('时间不能为空'));
      } else if (!integer_reg.test(value)) {
        callback(new Error('必须是大于等于0的整数'));
      } else {
        callback();
      }
    },
    checkMoney(rule, value, callback) {
      if (value === '') {
        callback(new Error('金额不能为空'));
      } else {
        const v = Number(value)
        if (!(v >= 0)) {
          callback(new Error('必须大于等于0'));
        } else {
          callback();
        }
      }
    }
  }
};
